<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区 -->
    <el-card>
        <!-- 搜索行 -->
        <el-row :gutter="10">
            <el-col :span="8">
                <el-input placeholder="请输入内容">
                    <el-button slot="append" icon="el-icon-search"></el-button>
                </el-input>
            </el-col>
        </el-row>

        <!-- table表格区 -->
        <el-table
        :data="orderList"
        style="width: 100%"
        border stripe>
            <el-table-column type="index"></el-table-column>
            <el-table-column
                prop="order_number"
                label="订单编号"
                width="180">
            </el-table-column>
            <el-table-column
                prop="order_price"
                label="订单价格"
                width="180">
            </el-table-column>

            <!-- 是否付款列： -->
            <el-table-column
                prop="pay_status"
                label="是否支付"
                width="180">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
                    <el-tag type="danger" v-else>未付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column
                prop="is_send"
                label="是否发货"
                width="180">
            </el-table-column>

            <!-- 是否下单列：使用全局过滤器进行渲染 -->
            <el-table-column
                prop="create_time"
                label="下单时间"
                width="180">
                <template slot-scope="scope">
                    {{scope.row.create_time | dateFormat}}
                </template>
            </el-table-column>

            <!-- 操作栏，使用作用域插槽的形式接收数据 -->
            <el-table-column>
                <template>
                    <el-button type="primary" icon="el-icon-edit" circle @click="showEditDialog"></el-button>
                    <el-button type="success" icon="el-icon-location" circle @click="showProgress"></el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页区 -->
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>

        <!-- 修改地址对话框 -->
        <el-dialog
        title="修改地址"
        :visible.sync="editAddressDialogVisible"
        width="50%"
        @close="editAddressDialogClosed">
            <!-- form表单区 -->
            <el-form :model="editAddressForm" :rules="editAddressFormRules" ref="editAddressFormRef" label-width="100px">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader
                    v-model="editAddressForm.address1"
                    :options="cityData"
                    :props="{ expandTrigger: 'hover' }">
                    </el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="editAddressForm.address2"></el-input>
                </el-form-item>
            </el-form>

            <span slot="footer">
                <el-button @click="editAddressDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="editAddressDialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 展示物流进度的对话框 -->
        <el-dialog
        title="物流进度"
        :visible.sync="progressVisible"
        width="50%">
            <!-- timeline时间线 -->
            <el-timeline>
                <el-timeline-item
                v-for="(activity, index) in progressInfo"
                :key="index"
                :timestamp="activity.time">
                {{activity.context}}
                </el-timeline-item>
            </el-timeline>

        </el-dialog>

    </el-card>
  </div>
</template>

<script>
import cityData from '@/components/order/citydata'
export default {
    data(){
        return {
            queryInfo:{
                query:'',
                pagenum:1,
                pagesize:10
            },

            // 订单列表
            orderList:[],

            // 订单总数量
            total:1,

            // 控制修改地址对话框的显示与隐藏
            editAddressDialogVisible: false,

            // 修改地址的表单数据
            editAddressForm:{
                address1:[],
                address2:''
            },

            // 地址的省市县
            cityData,

            // 修改地址的表单数据的验证规则
            editAddressFormRules:{
                address1:[
                    { required: true, message: '请选择省市区县', trigger: 'blur' }
                ],
                address2:[
                    { required: true, message: '请输入详细地址', trigger: 'blur' }
                ]
            },

            // 控制物流进度对话框的显示与隐藏
            progressVisible: false,

            // 物流信息
            progressInfo: []

            
        }
    },
    created(){
        this.getOrderList();
    },
    components:{

    },
    methods:{
        async getOrderList(){
            const {data:res} = await this.$http.get('orders',{params:this.queryInfo});
            if(res.meta.status!==200) return this.$message.error('请求订单列表失败');
            this.orderList = res.data.goods;
            this.total = res.data.total;
            console.log(this.orderList);
            console.log(this.total);
        },

        // 分页的页面大小改变时触发
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize;
            this.getOrderList();
        },

        // 分页的页码值改变时触发
        handleCurrentChange(newNum) {
            this.queryInfo.pagenum = newNum;
            this.getOrderList();
        },

        // 点击编辑时，显示修改对话框
        showEditDialog() {
            this.editAddressDialogVisible = true;
        },

        // 对话框关闭时，重置对话框
        editAddressDialogClosed() {
            this.$refs.editAddressFormRef.resetFields();
        },


        // 显示物流进度对话框
        async showProgress() {

            // 先获取物流信息
            const {data:res} = await this.$http.get(`/kuaidi/1106975712662`)

            if(res.meta.status!==200) return this.$message.error('获取物流进度失败');

            this.progressInfo = res.data;
            this.progressVisible = true;
            // console.log(this.progressInfo);
        },

    }
}
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';


    .el-cascader{
        width:100%;
    }
</style>